#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string.h>
#define N 1024
int main(void)
{
    char Input[N];
    char name[32];
    char* arg[32];
    while(1)
    {
        gethostname(name,sizeof(name)-1);
        printf("[%s]# ",name);
        fgets(Input,N,stdin);
        Input[strlen(Input)-1]='\0';
        arg[0]=strtok(Input," ");
        int i=1;
        while(arg[i]=strtok(NULL," "))
        {
            i++;
        }

        pid_t id=fork();
        if(id==0)
        {
            execvp(arg[0],arg);
            exit(1);
        }
         
        int status;
        pid_t ret=waitpid(id,&status,0);
        if(ret>0)
        {
            printf("exit code :%d \n",(status>>8)&0xFF);
        }
        
    }
    return 0;
}
